package com.lfg.leetcode.leetcode0;


public class No58lengthOfLastWord {

    public static void main(String[] args) {


        int ret = lengthOfLastWord("xx xx ");
        System.out.println(ret);
    }

    public static int lengthOfLastWord(String s) {
        if (null == s || "".equals(s)) {
            return 0;
        }
        int ret = 0;
        int i = s.length() - 1;

        for (; i >= 0; i--) {
            if (s.charAt(i) != ' ') {
                break;
            }
        }
        for (; i >= 0; i--) {
            if (s.charAt(i) == ' ') {
                break;
            }
            ret++;
        }
        return ret;
    }
}

